package com.healthtop.dao;


import com.healthtop.mapper.XsResourceMapper;
import com.healthtop.model.XsResource;
import com.healthtop.model.XsResourceExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class XsResourceDao {

    @Autowired
    private XsResourceMapper resourceMapper;

    public XsResource getResourceById(long id) {
        return resourceMapper.selectByPrimaryKey(id);
    }

    public List<XsResource> selectParentResource() {
        XsResourceExample resourceExample = new XsResourceExample();
        resourceExample.createCriteria().andPidEqualTo(0L).andStatusEqualTo(0);
        return resourceMapper.selectByExample(resourceExample);
    }

    public List<XsResource> selectResourceByPid(long parentId) {
        XsResourceExample resourceExample = new XsResourceExample();
        resourceExample.createCriteria().andPidEqualTo(parentId).andStatusEqualTo(0);
        return resourceMapper.selectByExample(resourceExample);
    }

    public void insertSelective(XsResource resource) {
        resourceMapper.insertSelective(resource);
    }

    public void update(XsResource resource) {
        resourceMapper.updateByPrimaryKeySelective(resource);
    }

}
